import socket

host = "localhost"
port = 6677
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((host, port))
    while True:
        data = input("请输入:")
        s.sendall(data.encode())
        recv = s.recv(1024)
        if not recv:
            print("服务器关闭")
            break
        if data in ("q","exit"):
            print("退出客户端")
            break
        print("recv:", recv.decode())
